package com.atguigu;

import org.junit.jupiter.api.Test;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;

@SpringBootTest
public class test {

    // 在简单模式下，默认交换机：名称是空串
    public static final String EXCHANGE_DIRECT = "";

    // 路由key: 在简单消息模式下，路由key就是队列名称。通过默认交换机进行转发消息的。
    public static final String ROUTING_KEY_SIMPLE = "atguigu.queue.simple";

    @Autowired
    RabbitTemplate rabbitTemplate; //SpringBoot自动化配置生成的，直接注入就可以使用。用于发送消息。


    //队列模式
    @Test
    public void testSendMessage(){
        rabbitTemplate.convertAndSend(EXCHANGE_DIRECT,ROUTING_KEY_SIMPLE,"hello,rabbit...");
    }
    public static final String EXCHANGE_DIRECT2 = "";
    public static final String ROUTING_KEY_WORK = "atguigu.queue.work";
    @Test
    public void testSendMessage1(){
        for (int i = 0; i < 10; i++) {
            rabbitTemplate.convertAndSend(EXCHANGE_DIRECT2,ROUTING_KEY_WORK,"hello,rabbit...i="+i);
        }

    }
    //广播模式
    public static final String EXCHANGE_FANOUT = "atguigu.exchange.fanout";

    @Test
    public void testSendMessageFanout() {
        rabbitTemplate.convertAndSend(EXCHANGE_FANOUT, "", "Hello fanout ~");
    }
    public static final String EXCHANGE_DIRECT3 = "atguigu.exchange.direct";

    public static final String ROUTING_KEY_GOOD = "atguigu.routing.key.good";

    @Test
    public void testSendMessageRouting() {
        rabbitTemplate.convertAndSend(EXCHANGE_DIRECT3, ROUTING_KEY_GOOD, "Hello routing ~");
    }

    public static final String EXCHANGE_TOPIC = "atguigu.exchange.topic";
    public static final String ROUTING_KEY_ERROR = "#.error";
    public static final String ROUTING_KEY_ORDER = "order.*";
    public static final String ROUTING_KEY_ALL = "*.*";

    @Test
    public void testSendMessageTopic() {
        rabbitTemplate.convertAndSend(EXCHANGE_TOPIC, "order.info", "message order info ...");
        rabbitTemplate.convertAndSend(EXCHANGE_TOPIC, "goods.info", "message goods info ...");
        rabbitTemplate.convertAndSend(EXCHANGE_TOPIC, "goods.error", "message goods error ...");
    }

}
